import dayjs from 'dayjs';

const dayjs2Date = (value: any, format: string = 'YYYY-MM-DD') => {
  if (!value) {
    return null;
  }
  return dayjs(dayjs(value).format(format), format).format('YYYY-MM-DD HH:mm:ss');
};

const date2Dayjs = (date: string, format: string = 'YYYY-MM-DD') => {
  if (!date) {
    return null;
  }
  return dayjs(date, format);
};

const getDateText = (value: any) => {
  let text: string = dayjs2Date(value) || '';
  if (text) {
    text = text.substring(0, 10);
  }
  return text;
};

export { dayjs2Date, date2Dayjs, getDateText };
